<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Attend extends AdminController
{

    function __construct()
    {
        parent::__construct();
        $this->load->model("Attend_model");
        $this->load->model("Select_model");        
//      $this -> sidebar = "Account-Admin";
    }

    public function Index($teacher_name=false)
    {
        $data=array();
        if($teacher_name){
            $data['teacher_name']=urldecode($teacher_name);
        }

		// 控制筛选项部门
        $deptlist=(new AdminDeptList)->getRemark()[0];
		for ($i=0; $i <count($deptlist) ; $i++) { 
			$deptlist[$i]='"'.$deptlist[$i].'"';
		}
        $connar['items']='distinct(dept_name)';
		$connar['where']="dept_name in(".implode(',',$deptlist).")";
        $dept_name=$this->Admin_model->get_list_full($connar);
        $new_dept_name=array();
        foreach($dept_name as $k=>$v){
            if($v['dept_name']){
                $name = mb_substr($v['dept_name'],0,2,"utf-8");             
                if($name =='财经' ||$name =='商贸'||$name =='交通'||$name =='鉴湖'||$name =='黄酒'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,2,"utf-8");             
                }else if($name =='建筑' ||$name =='机电'||$name =='交通'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,4,"utf-8");   
                }else if($name =='设计'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,5,"utf-8");   
                }else{
                    $new_dept_name[$k]['name'] = $v['dept_name'];
                }
                 $new_dept_name[$k]['dept_name'] = $v['dept_name'];
            }
            

        }

         //获取开课单位
         $data['course_units'] = (new AdminDeptList)->getRemark()[1]; 

        $data['dept_name']= $new_dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));
        $data['class_type']=$this -> Select_model -> get_list(array('type'=>SelectType::CourseType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));

        $this->load->view('admin/attendList',$data);
    }

    function getDatas($params = array(), $isExport = false)
    {
        
        $connar = array();
        if (!$isExport) {
            $params = $_POST;
            $connar = $this->Attend_model->pickPages($connar, $params);
        }  

        $sub_role=explode(',', getSess()['sub_role_id']);
         array_push($sub_role, getSess()['role_id']);
        $sub_role= array_merge(array_filter($sub_role));	
        // 不同时是校督导督导组长
        if(!(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $sub_role) && in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $sub_role))){ 
            $connar['items'] = "db_attend.*,db_admin.major major,db_admin.dept_name listen_dept_name,db_admin.usercode listen_code";
            $connar['join'][0]=array('db_admin ','db_admin.id = db_attend.listen_id'); 
            // $connar['join'][1]=array('db_class','db_class.name = db_attend.class_name  and db_class.teacher_id = db_attend.teacher_code');
            //$connar['join'][2]=array('db_attend_record','db_attend.id=db_attend_record.attend_id'); 
            //   $connar['where']=$this->sqlEscape('if(db_attend.listen_id=??,db_attend.status=?? or db_attend.status=??,if(back_time is null,db_attend.STATUS = ?? or db_attend.STATUS = ??, db_attend.STATUS = ?? or db_attend.STATUS = ??) )',array(getSess()['id'],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
            $connar['where']= ' db_attend.`status` > 0 ';
            $connar['orderby'] = "back_time desc, db_attend.id desc ";

            //管理员,,校领导,看到全校的听课数据
            if(in_array(WebRole::Manage[XPHEnum::Value], $sub_role) || in_array(WebRole::Admin[XPHEnum::Value], $sub_role)  || in_array(WebRole::SchoolLeader[XPHEnum::Value], $sub_role) || in_array(WebRole::SupervisorDirector[XPHEnum::Value], $sub_role)){
                // $connar['where'].=" and 1=1";
            }else if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $sub_role)){                
                //督导组长看到本分院的听课数据          
                if(in_array(WebRole::UnitLeader[XPHEnum::Value], $sub_role)){//同时是职能部门及二级教学单位负责人                  
                     if(getSess()['dept_id']==123 || getSess()['dept_id']==107){ // 教务处/质量管理可以看到全校    
                    //    $connar['where'].=" and 1=1";
                     }else{
                         $connar['join'][1]=array('db_admin admin','admin.id='.getSess()['id']);
                        // $connar['where']=$this->sqlEscape('if(db_attend.listen_id=??,db_attend.status=?? or db_attend.status=??,IF ( admin.role_id = ?? OR find_in_set(??,admin.sub_role_id) , db_attend.STATUS =??  OR db_attend.STATUS =??, db_attend.STATUS = ?? ))',array(getSess()['id'],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],WebRole::UnitLeader[XPHEnum::Value],WebRole::UnitLeader[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
                       $connar['where'].=$this->sqlEscape(' and (db_admin.dept_id=?? or db_attend.dept_name=??) and (db_attend.type=?? or db_attend.type=?? or db_attend.type=?? or db_attend.type=?? or db_attend.type=??)',array(getSess()['dept_id'],str_replace('分', '学', getSess()['dept_name']),AttendType::Unit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value],AttendType::Teacher[XPHEnum::Value],AttendType::UnitLeader[XPHEnum::Value],AttendType::MajorUnitLeader[XPHEnum::Value]));

                     }

                }else{
                    //  $connar['where']=$this->sqlEscape('if(db_attend.listen_id=??,db_attend.status=?? or db_attend.status=??,IF ( db_admin.role_id = ?? AND ( sub_role_id IS NULL OR sub_role_id = "" ), db_attend.STATUS =??  OR db_attend.STATUS =??, db_attend.STATUS = ?? ))',array(getSess()['id'],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],WebRole::Teacher[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
                       $connar['where'].=$this->sqlEscape(' and (db_admin.dept_id=?? or db_attend.dept_name=??) and (db_attend.type=?? or db_attend.type=?? or db_attend.type=?? or db_attend.type=?? or db_attend.type=??)',array(getSess()['dept_id'],str_replace('分', '学', getSess()['dept_name']),AttendType::Unit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value],AttendType::Teacher[XPHEnum::Value],AttendType::UnitLeader[XPHEnum::Value],AttendType::MajorUnitLeader[XPHEnum::Value]));
                       //当没有专业负责人或二级教学单位负责人时，督导组长不可查看未提交的教师听课数据
                    if(!in_array(WebRole::MajorUnitLeader[XPHEnum::Value], $sub_role) && !in_array(WebRole::UnitLeader[XPHEnum::Value], $sub_role)){
                        $connar['where'] .= $this->sqlEscape(" and db_attend.type <>?? ",array(AttendType::Teacher[XPHEnum::Value]));
                    }
                }
              
            }else if(in_array(WebRole::MajorUnitLeader[XPHEnum::Value], $sub_role)){
                 //专业负责人查看本专业的数据,不是专业负责人查看自己听课的数据
                 $connar['where'].=$this->sqlEscape(' and db_admin.major=??',array(getSess()['major']));     
            }elseif(in_array(WebRole::UnitLeader[XPHEnum::Value], $sub_role)){//分院领导看自己部门的数据
                 // 教务处/质量管理可以看到全校,其他人看到本分院
                if(getSess()['dept_id']!=123 && getSess()['dept_id']!=107){
                    $connar['where'].=$this->sqlEscape(' and db_admin.dept_id=??',array(getSess()['dept_id']));
                }
            }else{//教师看到自己的听课数据
                  $connar['where'].=$this->sqlEscape(' and db_attend.listen_id=??',array(getSess()['id']));    
            }
            // pri($connar);
            // exit;
            //课程名称
            if (isset($_POST['class_name']) && $_POST['class_name'] != ''){           
                $connar['where'] .= $this->sqlLikeEscape(" and db_attend.class_name like '%??%' ", array($_POST['class_name']));
            }
            //教师名称
            if(isset($_POST['teacher_name']) && $_POST['teacher_name'] != ''){
                $connar['where'] .= $this->sqlLikeEscape(" and db_attend.teacher_name like '%??%' ", array($_POST['teacher_name']));
            }
            //听课班级
            if(isset($_POST['listen_class']) && $_POST['listen_class'] != ''){
                $connar['where'] .= $this->sqlLikeEscape(" and db_attend.listen_class like '%??%' ", array($_POST['listen_class']));
            }
            //职称
            if(isset($_POST['title'])&&$_POST['title']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.title=?? ",array($_POST['title']));
            }
            //课程类型
            if(isset($_POST['class_type'])&&$_POST['class_type']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.class_type=?? ",array($_POST['class_type']));
            }
            //听课督导
            if(isset($_POST['listen_name']) && $_POST['listen_name'] != '')
            {
                $connar['where'] .= $this->sqlLikeEscape(" and db_admin.username like '%??%' ",array($_POST['listen_name']));
            }
            //督导听课身份类型
            if(isset($_POST['type'])&&$_POST['type']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.type=?? ",array($_POST['type']));
            }
            //听课类型
            if(isset($_POST['listen_type'])&&$_POST['listen_type']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.listen_type=?? ",array($_POST['listen_type']));
            }

            if (isset($_POST['start_time']) && isset($_POST['end_time']) && $_POST['start_time'] != '' && $_POST['end_time'] != '') {

                $connar['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');

            }
             //教师所属分院名称
             if(isset($_POST['dept_name'])&&$_POST['dept_name']>-1)
            {
                 $connar['where'] .= " and db_attend.dept_name like '%".$_POST['dept_name']."%'";
                 // $connar['where'] .= $this->sqlEscape(" and (db_attend.dept_name=?? or db_attend.dept_name=??)",array(str_replace('分', '学', $_POST['dept_name']),str_replace('学', '分', $_POST['dept_name'])));
            }  
             //开课单位名称
             if(isset($_POST['course_units'])&&$_POST['course_units']>-1)
            {
                 $connar['where'] .= " and db_attend.course_units like '%".$_POST['course_units']."%'";
                 // $connar['where'] .= $this->sqlEscape(" and (db_attend.dept_name=?? or db_attend.dept_name=??)",array(str_replace('分', '学', $_POST['dept_name']),str_replace('学', '分', $_POST['dept_name'])));
            }           
            // 听课记录
            if(isset($_POST['content']) && $_POST['content'] != '')
            {
                $connar['where'] .= $this->sqlLikeEscape(" and db_attend_record.commentary like '%??%' ",array($_POST['content']));
            }   
            //提交状态
            if (isset($_POST['is_submit'])&& $_POST['is_submit'] > -1){

                  $connar['where'] .= $this->sqlEscape(" and db_attend.status=?? ",array($_POST['is_submit']));
            }

            //提交状态
            if (isset($_POST['is_complete'])&& $_POST['is_complete'] > -1){
                if($_POST['is_complete'] == 1){
                    // if ($v['course_units'] == '' || $v['listen_time'] == '' || $v['class_name'] == '' || $v['teacher_name'] == '' || $v['dept_name'] == '' || $v['title'] == '' || $v['teachers_attribute'] == '' || $v['class_type'] == '' || $v['listen_class'] == '' || $v['listen_address'] == '' || $v['type'] == '' || $v['listen_type'] == '' || $v['teaching_level_score'] == '0' || $v['teaching_effect_score'] == '0' || $v['score'] == '0') {
                    $connar['where'] .= $this->sqlEscape(" and (db_attend.course_units!='' and db_attend.listen_time!='' and db_attend.listen_time != '0' and db_attend.class_name!='' and db_attend.teacher_name!='' and db_attend.dept_name!='' and db_attend.listen_time!='' and db_attend.title!='' and db_attend.teachers_attribute!='' and db_attend.class_type!='' and db_attend.listen_class!='' and db_attend.listen_address!='' and db_attend.type!='' and db_attend.listen_type!='' and db_attend.teaching_level_score!='0' and db_attend.teaching_effect_score!='0' and db_attend.score!='0')",array());
                }else{
                    $connar['where'] .= $this->sqlEscape(" and (db_attend.course_units='' or db_attend.listen_time='' or db_attend.listen_time = '0'  or db_attend.class_name='' or db_attend.teacher_name='' or db_attend.dept_name='' or db_attend.listen_time='' or db_attend.title='' or db_attend.teachers_attribute='' or db_attend.class_type='' or db_attend.listen_class='' or db_attend.listen_address='' or db_attend.type='' or db_attend.listen_type='' or db_attend.teaching_level_score='0' or db_attend.teaching_effect_score='0' or db_attend.score='0')",array());
                }
               
          }

            

            //总分筛选
            if(isset($_POST['score'])&& $_POST['score'] > -1){

                if($_POST['score'] == TotalSorce::First[XPHEnum::Value]){
                    $connar['where'] .= $this->sqlEscape(" and db_attend.score >=?? ",array(TotalSorce::First[XPHEnum::Remark])); 
                }else if($_POST['score'] == TotalSorce::Second[XPHEnum::Value]){
                    $score = explode('-',TotalSorce::Second[XPHEnum::Remark]);
                     $connar['where'] .= $this->sqlEscape(" and db_attend.score >=??  and db_attend.score < ??  ",array($score[0],$score[1])); 
                }else{
                    $connar['where'] .= $this->sqlEscape(" and db_attend.score < ?? ",array(TotalSorce::Third[XPHEnum::Remark])); 
                }
            }

            if (!$isExport) {
                $data = $this->Attend_model->get_page_list($connar);
                    // echo $this->db->last_query();
            } else {
                // 为了导出大数据
                ini_set('memory_limit', '1024M');
                $data["ret"] = $this->Attend_model->get_list_full($connar);
                // echo $this->db->last_query();exit;
            
            }            
        }
        else{
         
            // 同时是校督导督导组长
            if(in_array(WebRole::Manage[XPHEnum::Value], $sub_role)){
                $where = 'where db_attend.`status`  > 0 ';
                // $where= $this->sqlEscape("where db_attend.status=??", array(AttendStatus::Submit[XPHEnum::Value]));
                // $where =$this->sqlEscape(' where if(db_attend.listen_id=??,db_attend.status=?? or db_attend.status=??,if(back_time is null,db_attend.STATUS = ?? or db_attend.status=??, db_attend.STATUS = ?? or db_attend.STATUS = ??) )',array(getSess()['id'],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
            }else{
                // $where=$this->sqlEscape('where if(db_attend.listen_id=??,db_attend.status=?? or db_attend.status=??,IF ( db_admin.role_id = ?? AND ( sub_role_id IS NULL OR sub_role_id = "" ), db_attend.STATUS =??  OR db_attend.STATUS =??, if(back_time is null,db_attend.STATUS = ?? OR db_attend.STATUS = ??, db_attend.STATUS = ?? or db_attend.STATUS = ??)))',array(getSess()['id'],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],WebRole::Teacher[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
                  if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $sub_role) && !in_array(WebRole::UnitLeader[XPHEnum::Value], $sub_role)){ 
                    //  $where .=$this->sqlEscape(' and (db_admin.dept_id=?? or db_attend.dept_name=??)',array(getSess()['dept_id'],str_replace('分', '学', getSess()['dept_name'])));
					// $where .=$this->sqlEscape(' and (db_admin.dept_id=?? or db_attend.dept_name=?? or db_attend.course_units=??)',array(getSess()['dept_id'],str_replace('分', '学', getSess()['dept_name']),str_replace('分', '学', getSess()['dept_name'])));                 
					$where =$this->sqlEscape(' where db_attend.`status`  > 0 and (db_admin.dept_id=?? or db_attend.dept_name=?? or db_attend.course_units=??)',array(getSess()['dept_id'],str_replace('分', '学', getSess()['dept_name']),str_replace('分', '学', getSess()['dept_name'])));                 
				 }
                // $where.= $this->sqlEscape("  and dept_id=??", array(getSess()['dept_id']));
            }

            if(in_array(WebRole::UnitLeader[XPHEnum::Value], $sub_role)){ //其他分院领导
                // 教务处/质量管理可以看到全校,其他人看到本分院
                if(getSess()['dept_id']!=123 && getSess()['dept_id']!=107){
                      $where .=$this->sqlEscape(' and (db_admin.dept_id=?? or db_attend.dept_name=??)',array(getSess()['dept_id'],str_replace('分', '学', getSess()['dept_name'])));
                }
            }

            //专业负责人查看本专业的数据
            if(in_array(WebRole::MajorUnitLeader[XPHEnum::Value], $sub_role)){
               $where .=$this->sqlEscape(' and db_admin.major=??',array(getSess()['major']));
            }
            if (isset($_POST['class_name']) && $_POST['class_name'] != ''){           
                $where .= $this->sqlLikeEscape(" and db_attend.class_name like '%??%' ", array($_POST['class_name']));
            }
            //教师名称
            if(isset($_POST['teacher_name']) && $_POST['teacher_name'] != ''){
                $where .= $this->sqlLikeEscape(" and db_attend.teacher_name like '%??%' ", array($_POST['teacher_name']));
            }
            //听课班级
            if(isset($_POST['listen_class']) && $_POST['listen_class'] != ''){
                $where .= $this->sqlLikeEscape(" and db_attend.listen_class like '%??%' ", array($_POST['listen_class']));
            }
            //职称
            if(isset($_POST['title'])&&$_POST['title']>-1)
            {
                $where .= $this->sqlEscape(" and db_attend.title=?? ",array($_POST['title']));
            }
            //课程类型
            if(isset($_POST['class_type'])&&$_POST['class_type']>-1)
            {
                $where .= $this->sqlEscape(" and db_attend.class_type=?? ",array($_POST['class_type']));
            }
            //听课督导
            if(isset($_POST['listen_name']) && $_POST['listen_name'] != '')
            {
                $where .= $this->sqlLikeEscape(" and db_admin.username like '%??%' ",array($_POST['listen_name']));
            }
            //听课类型
            if(isset($_POST['type'])&&$_POST['type']>-1)
            {
                $where .= $this->sqlEscape(" and db_attend.type=?? ",array($_POST['type']));
            }
            
            //听课类型
            if(isset($_POST['listen_type'])&&$_POST['listen_type']>-1)
            {
                $where .= $this->sqlEscape(" and db_attend.listen_type=?? ",array($_POST['listen_type']));
            }

            if (isset($_POST['start_time']) && isset($_POST['end_time']) && $_POST['start_time'] != '' && $_POST['end_time'] != '') {

                $where.=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');

            } 
            
             //分院名称
             if(isset($_POST['dept_name'])&&$_POST['dept_name']>-1)
            {
                 $where .= " and db_attend.dept_name like '%".$_POST['dept_name']."%'";
                // $connar['where'] .= $this->sqlEscape(" and (db_attend.dept_name=?? or db_attend.dept_name=??)",array(str_replace('分', '学', $_POST['dept_name']),str_replace('学', '分', $_POST['dept_name'])));              
            }

             //开课单位名称
             if(isset($_POST['course_units'])&&$_POST['course_units']>-1)
            {
                $where .= " and db_attend.course_units like '%".$_POST['course_units']."%'";
                 // $connar['where'] .= $this->sqlEscape(" and (db_attend.dept_name=?? or db_attend.dept_name=??)",array(str_replace('分', '学', $_POST['dept_name']),str_replace('学', '分', $_POST['dept_name'])));
            }  
            // 听课记录
            if(isset($_POST['content']) && $_POST['content'] != '')
            {
                $where .= $this->sqlLikeEscape(" and db_attend_record.commentary like '%??%' ",array($_POST['content']));
            }
            //提交状态
            if (isset($_POST['is_submit'])&& $_POST['is_submit'] > -1){

                   $where .=  $this->sqlEscape(" and db_attend.status=?? ",array($_POST['is_submit']));
            }

              //总分筛选
            if(isset($_POST['score'])&& $_POST['score'] > -1){

                if($_POST['score'] == TotalSorce::First[XPHEnum::Value]){
                      $where .= $this->sqlEscape(" and db_attend.score >=?? ",array(TotalSorce::First[XPHEnum::Remark])); 
                }else if($_POST['score'] == TotalSorce::Second[XPHEnum::Value]){
                    $score = explode('-',TotalSorce::Second[XPHEnum::Remark]);
                      $where .= $this->sqlEscape(" and db_attend.score >=??  and db_attend.score < ??  ",array($score[0],$score[1])); 
                }else{
                     $where .= $this->sqlEscape(" and db_attend.score < ?? ",array(TotalSorce::Third[XPHEnum::Remark])); 
                }
            }

                //提交状态
            if (isset($_POST['is_complete'])&& $_POST['is_complete'] > -1){
                if($_POST['is_complete'] == 1){
                    // if ($v['course_units'] == '' || $v['listen_time'] == '' || $v['class_name'] == '' || $v['teacher_name'] == '' || $v['dept_name'] == '' || $v['title'] == '' || $v['teachers_attribute'] == '' || $v['class_type'] == '' || $v['listen_class'] == '' || $v['listen_address'] == '' || $v['type'] == '' || $v['listen_type'] == '' || $v['teaching_level_score'] == '0' || $v['teaching_effect_score'] == '0' || $v['score'] == '0') {
                        $where .= $this->sqlEscape(" and (db_attend.course_units!='' and db_attend.listen_time!='' and db_attend.listen_time != '0' and db_attend.class_name!='' and db_attend.teacher_name!='' and db_attend.dept_name!='' and db_attend.listen_time!='' and db_attend.title!='' and db_attend.teachers_attribute!='' and db_attend.class_type!='' and db_attend.listen_class!='' and db_attend.listen_address!='' and db_attend.type!='' and db_attend.listen_type!='' and db_attend.teaching_level_score!='0' and db_attend.teaching_effect_score!='0' and db_attend.score!='0')",array());
                }else{
                    $where .= $this->sqlEscape(" and (db_attend.course_units='' or db_attend.listen_time='' or db_attend.listen_time = '0'  or db_attend.class_name='' or db_attend.teacher_name='' or db_attend.dept_name='' or db_attend.listen_time='' or db_attend.title='' or db_attend.teachers_attribute='' or db_attend.class_type='' or db_attend.listen_class='' or db_attend.listen_address='' or db_attend.type='' or db_attend.listen_type='' or db_attend.teaching_level_score='0' or db_attend.teaching_effect_score='0' or db_attend.score='0')",array());
                }
                
            }

            if(!$isExport){
                $pageSize=$_POST['pageSize'];
                $pageNo=$_POST['pageNo'];
            }else{
                $pageSize='999999999';
                $pageNo=1;
            }

            if(isset($_POST['teacher_name'])){
                $sql=$this->sqlLikeEscape("select * from (select `db_attend`.*,db_attend.id attend_id,db_admin.major major,db_admin.dept_name listen_dept_name ,db_admin.usercode listen_code FROM `db_attend` LEFT JOIN `db_admin` ON `db_admin`.`id` = `db_attend`.`listen_id`".$where ." union SELECT `db_attend`.*,db_attend.id attend_id,db_admin.major major,
            db_admin.dept_name listen_dept_name,db_admin.usercode listen_code FROM `db_attend` LEFT JOIN `db_admin` ON `db_admin`.`id` = `db_attend`.`listen_id`  WHERE `db_attend`.`status` = ??  and `db_attend`.`type` = ?? and db_attend.listen_name='??'   and db_attend.teacher_name like '%??%') a  order by a.back_time desc,a.id desc limit ".$pageSize* ($pageNo-1) .','.$pageSize,array(AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value],getSess()['username'],$_POST['teacher_name']));
                $sql1=$this->sqlLikeEscape("select sum(count) as count from (select count(*) as count FROM `db_attend` LEFT JOIN `db_admin` ON `db_admin`.`id` = `db_attend`.`listen_id` ".$where ." union SELECT count(*) as count FROM `db_attend` LEFT JOIN `db_admin` ON `db_admin`.`id` = `db_attend`.`listen_id`  WHERE `db_attend`.`status` = ??  and `db_attend`.`type` = ?? and db_attend.listen_name='??' and db_attend.teacher_name like '%??%' ) count",array(AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value],getSess()['username'],$_POST['teacher_name']));
            }else{
                 $sql=$this->sqlEscape("select `db_attend`.*,db_attend.id attend_id,db_admin.major,db_admin.dept_name listen_dept_name,db_admin.usercode listen_code FROM `db_attend` LEFT JOIN `db_admin` ON `db_admin`.`id` = `db_attend`.`listen_id`".$where ." order by  back_time desc,db_attend.id desc  limit ".$pageSize* ($pageNo-1) .','.$pageSize,array());
                $sql1=$this->sqlEscape("select sum(count) as count from (select count(*) as count FROM `db_attend` LEFT JOIN `db_admin` ON `db_admin`.`id` = `db_attend`.`listen_id` ".$where ." ) count",array());
            }     


            $data["ret"]=$this->Attend_model->query($sql);
            $count=$this->Attend_model->query($sql1);
            $data['count']=$count[0]['count'];
            $data['pageNo']=$pageNo;
            $data['totalPage']=ceil($data["count"] / $pageSize);
        }
       
        foreach ($data['ret'] as $k => $v) {
            //管理员可以退回
             if((in_array(WebRole::Admin[XPHEnum::Value], $sub_role) || in_array(WebRole::Manage[XPHEnum::Value], $sub_role)) && $v['status'] == AttendStatus::Submit[XPHEnum::Value] && $v['created']>'1628179200'){
                $data['ret'][$k]['is_show']= 1;
             }else{
                if($v['status'] == AttendStatus::Submit[XPHEnum::Value]){
                    $data['ret'][$k]['is_show']= 1;
                }else{
                    $data['ret'][$k]['is_show']= 2;
                }                 
             }
             $v['teacher_code'] = isset($v['teacher_code']) && $v['teacher_code']!=''?$v['teacher_code']:'无';
             $v['listen_code'] = isset($v['listen_code']) && $v['listen_code']!=''?$v['listen_code']:'无';
             $data['ret'][$k]['teacher_name'] =$v['teacher_name']? $v['teacher_name'].'['. $v['teacher_code'].']':'';
             $data['ret'][$k]['listen_name'] =$v['listen_name']? $v['listen_name'].'['.$v['listen_code'].']':'';
             
             
        //            $attend_listen_time='';
        //            if($v['listen_time']&&$v['listen_time']!=''){
        //                $attend_listen_time.=date('Y-m-d',$v['listen_time']);
        //            }
        //            else{
        //                $attend_listen_time.='开始时间未设置';
        //            }

                    // $data['ret'][$k]['class_name'] = (new CourseName())->show($data['ret'][$k]['class_name']);
                    // $data['ret'][$k]['age_groups'] = (new AgeGroups())->show($data['ret'][$k]['age_groups']);
                    // $data['ret'][$k]['teachers_attribute'] = (new TeachersAttribute())->show($data['ret'][$k]['teachers_attribute']);
                    // $data['ret'][$k]['title'] = (new Title())->show($data['ret'][$k]['title']);
                    $data['ret'][$k]['listen_time'] = $data['ret'][$k]['listen_time']==0?'':date('Y-m-d ', $data['ret'][$k]['listen_time']);
        //            $data['listen_time']=date('Y-m-d',$attend_listen_time['listen_time']);
                    $data['ret'][$k]['type_char']=(new AttendType)->show($v['type']);
                    $data['ret'][$k]['status_char']=(new AttendStatus)->show($v['status']);            
                    if($v['back_time']){
                        $data['ret'][$k]['color']='red';
                        if($v['status']==AttendStatus::Submit[XPHEnum::Value]){
                            $data['ret'][$k]['status_char']='退回后提交';
                        }else{                    
                            $data['ret'][$k]['status_char']='退回中<br/>(理由：'.$v['back_remark'].')';
                        }
                    }

                    if ($v['course_units'] == '' || $v['listen_time'] == ''|| $v['listen_time'] == '0' || $v['class_name'] == '' || $v['teacher_name'] == '' || $v['dept_name'] == '' || $v['title'] == '' || $v['teachers_attribute'] == '' || $v['class_type'] == '' || $v['listen_class'] == '' || $v['listen_address'] == '' || $v['type'] == '' || $v['listen_type'] == '' || $v['teaching_level_score'] == '0' || $v['teaching_effect_score'] == '0' || $v['score'] == '0') {
                        $data['ret'][$k]['is_complete']='否';
                    }else{
                        $data['ret'][$k]['is_complete']='是';
                    }
        }


        if (!$isExport) {
          //  pri($data);
            echo json_encode($data);
        } else {

           
            $this-> load ->library('PHPExcel/PHPExcel');
            $excel = new PHPExcel();
            //公共样式
            $excel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(11); 
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setWrapText(true);
            $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(23);
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $excel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);

            $x_line=0;
            $y_line=1;
            
            //标题
            // var_dump($data['ret']);
            // $title=array('开课单位','督导听课人数','督导听课次数','校督导听课人数','校督导听课次数','教学水平平均分','教学效果平均分','教学水平90分(含)以上','教学水平80以下','教学效果90分(含)以上','教学效果80以下','教学水平最高分','教学水平最低分','教学效果最高分','教学效果最低分');
            // foreach ($title as $k => $v) {
            //     $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v);
            //     $excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line)->getFont()->setBold(true);   
            //     $x_line++;
            // }

            // $x_line=0;
            // $y_line=2;
            // //正式数据
            // foreach ($data['ret'] as $k => $v) {            
            //     foreach ($v as $k1 => $v1) {
            //         $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v1);


            //         $x_line++;
            //     }
            //     $x_line=0;
            //     $y_line++;
            // }

            //正式开始
            $excel = new PHPExcel();
            $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(15);
            
            //标题
            $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0).'1:'.PHPExcel_Cell::stringFromColumnIndex(15).'1');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).'1','课堂教学评价');
            $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
            $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
            $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $i=2;
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$i,'听课教师名称');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$i,'授课教师名称');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$i,'教学能力总分');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$i,'学生状况总分');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(4).$i,'总分');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(5).$i,'学年');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(6).$i,'学期');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(7).$i,'听课身份');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(8).$i,'课程名称');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(9).$i,'课程类型');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(10).$i,'职称');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(11).$i,'所属二级学院（部）');
          //  $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$i,'年龄层次');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$i,'教师属性');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(13).$i,'听课类型');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(14).$i,'听课时间');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(15).$i,'开课单位');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(16).$i,'课程编号');
        

            $i++;
            foreach ($data['ret'] as $k => $v) {


           // 自定义 SQL 查询
            $sql = "SELECT * FROM db_class WHERE name  like ?  LIMIT 1";
            $query = $this->db->query($sql, [ '%'.$v['class_name'].'%']); // 第二个参数是绑定参数
          
            // 获取单条数据
            $row = $query->row();

            if ($row) {
                // 访问字段值
               $class_code = $row->code;
            } else {
                $class_code  = "";
            }

                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$i,$v['listen_name']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$i,$v['teacher_name']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$i,$v['teaching_level_score']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$i,$v['teaching_effect_score']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(4).$i,$v['score']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(5).$i,$v['academic_year']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(6).$i,$v['semester']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(7).$i,$v['type_char']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(8).$i,$v['class_name']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(9).$i,$v['class_type']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(10).$i,$v['title']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(11).$i,$v['dept_name']);
              //      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$i,$v['age_groups']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$i,$v['teachers_attribute']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(13).$i,$v['listen_type']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(14).$i,$v['listen_time']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(15).$i,$v['course_units']);
                $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(16).$i,$class_code);
            
                $i++;
            }
            //设置对齐
            $excel->getActiveSheet()->getStyle('A1:'.PHPExcel_Cell::stringFromColumnIndex(9).($i-1))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $excel->getActiveSheet()->getStyle('A1:'.PHPExcel_Cell::stringFromColumnIndex(0).($i-1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);


                $write = new PHPExcel_Writer_Excel2007($excel); 
                $director = "upload/export/" . date('Ymd', time()) . "/";
                if (!file_exists($director)) {
                    //检查是否有该文件夹，如果没有就创建，并给予最高权限
                    mkdir($director, 0777);
                }        
                $file_name ='督导听课'.date('Ymdhis').'.xlsx';           
                $write->save($director.iconv('utf-8', 'gb2312', $file_name));
                exit(retJson('返回地址',true,$director.$file_name));
                // return $data["ret"];
        }
    }

    //新增，修改
    function edit($id)
    {
        //角色数组
        $this->load->model("Attend_model");
        $this->load->library("ProjectService/attend_service");
        $this->load->model('Select_model');
        $connar['where'] = " id<>1 ";
        // $data['role'] = $this->Attend_model->get_list_full($connar);

        //        if ($id == 0) {
        //            $data['title'] = "新增听课";
        //            $data['detail'] = $this->Attend_model->get_single(array("id" => $id));
        //        } else {
                $data['title'] = "督导听课评价表";
                $data['detail']=$this->attend_service->getAttendData($id,false,false,$_GET['type']);
                $data['courseType']=$this->Select_model->get_list(array('type'=>SelectType::CourseType[XPHEnum::Value]));
        //            $data['detail'] = $this->Attend_model->get_single(array("id" => $id));
        //        }
            if($data['detail']['attend']['cc_type'] == '2' && $data['detail']['attend']['created']>1660548484){
                $this->load->view('admin/attendEdit3', $data);
            }else if($data['detail']['attend']['cc_type'] == '3'){
                $this->load->view('admin/attendEdit4', $data);
            }else if($data['detail']['attend']['cc_type'] == '4'){
                $this->load->view('admin/attendEdit5', $data);
            }else{
                if($data['detail']['attend']['created']<1587744000){ //2020-04-25  老页面样式
                    // 老页面数据
                    $this->load->view('admin/attendEdit', $data);
                }elseif($data['detail']['attend']['created']>1627526560){
                    // 新页面2021-07-29 10:42:40
                    // 20219月新课标
                    // pri($data);exit;
                    $this->load->view('admin/attendEdit2', $data);
                }else{
                    // 老页面数据
                    $this->load->view('admin/attendEdit1', $data);
                }
            }
               

        
    }

    //新增修改操作
//    function save()
//    {
//        $_POST = $this->NOTXSS_POST;
//
//        if (!isset($_POST['title'])) {
//            exit(retJson("请填写标题.", false));
//        }
//        if (!isset($_POST['role_id_str'])) {
//            exit(retJson("请选择可见角色.", false));
//        }
//        if ($_POST['start'] == '') {
//            exit(retJson("请选择开始时间.", false));
//        }
//        if ($_POST['end'] == '') {
//            exit(retJson("请选择结束时间.", false));
//        }
//
//        $announcement = copyArray($_POST, array("id", "title", 'start', 'end', 'role_id_str', 'content'));
//        if ($announcement['start'] != '') {
//            $announcement['start'] = strtotime($announcement['start'] . ' 00:00:00');
//        }
//        if ($announcement['end'] != '') {
//            $announcement['end'] = strtotime($announcement['end'] . ' 23:59:59');
//        }
//        if ($announcement['end'] < $announcement['start']) {
//            exit(retJson("结束时间必须大于开始时间.", false));
//        }
//        $announcement['role_id_str'] = implode(',', $announcement['role_id_str']);
//
//        if (!isset($_POST['id']) || $_POST['id'] == "") {
//
//            $announcement['status'] = CommonStatus::UnDeleted[XPHEnum::Value];
//            $announcement['creator'] = getSess()['id'];
//            $announcement['created'] = time();
//            $this->Announcement_model->add($announcement);
//            $isAdd = 1;
//
//
//            exit(retJson("添加成功.", true, $isAdd));
//        } else {
//
//
//            $isAdd = 0;
//            $announcement['updated'] = time();
//            $this->Announcement_model->update($announcement);
//
//            exit(retJson("修改成功.", true, $isAdd));
//        }
//    }

    function delete($id)
    {
        $this->Attend_model->update(array('id' => $id, 'status' => AttendStatus::Deleted[XPHEnum::Value]));
        exit(retJson("删除成功.", true));
    }  


  function reply($id)
    {
        $reason = $_POST['reason'];
        $this->Attend_model->update(array('id' => $id, 'status' => AttendStatus::Save[XPHEnum::Value],'back_time'=>time(),'back_remark'=>$reason));
        exit(retJson("退回成功.", true));
    } 

    // 领导听课
    function leaderIndex(){
        $data=array();

        $connar['items']='distinct(dept_name)';
        $dept_name=$this->Admin_model->get_list_full($connar);

        $data['dept_name']= $dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));

        $data['role']=WebRole::SchoolLeader[XPHEnum::Value];
        $data['type']=1;
        $this->load->view('admin/attendListNew',$data);
    }

    // 专业负责人听课
    function majorIndex(){
        $data=array();

        $connar['items']='distinct(dept_name)';
        $dept_name=$this->Admin_model->get_list_full($connar);

        $data['dept_name']= $dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));

        $data['role']=WebRole::MajorUnitLeader[XPHEnum::Value];
        $data['type']=1;
        $this->load->view('admin/attendListNew',$data);
    }

    // 教师听课
    function teacherIndex(){
        $data=array();

        $connar['items']='distinct(dept_name)';
        $dept_name=$this->Admin_model->get_list_full($connar);

        $data['dept_name']= $dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));
        
        $data['role']=WebRole::Teacher[XPHEnum::Value];
        $data['type']=1;
        $this->load->view('admin/attendListNew',$data);
    }

    // 领导听课
    function leaderIndex1(){
        $data=array();

        $connar['items']='distinct(dept_name)';
        $dept_name=$this->Admin_model->get_list_full($connar);

        $data['dept_name']= $dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));

        $data['role']=WebRole::SchoolLeader[XPHEnum::Value].','.WebRole::UnitLeader[XPHEnum::Value];
        $data['type']=2;
        $this->load->view('admin/attendListNew1',$data);
    }

    // 专业负责人听课
    function majorIndex1(){
        $data=array();

        $connar['items']='distinct(dept_name)';
        $dept_name=$this->Admin_model->get_list_full($connar);

        $data['dept_name']= $dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));

        $data['role']=WebRole::MajorUnitLeader[XPHEnum::Value];
        $data['type']=2;
        $this->load->view('admin/attendListNew1',$data);
    }

    // 教师听课
    function teacherIndex1(){
        $data=array();

        $connar['items']='distinct(dept_name)';
        $dept_name=$this->Admin_model->get_list_full($connar);
         $new_dept_name=array();
        foreach($dept_name as $k=>$v){
            if($v['dept_name']){
                $name = mb_substr($v['dept_name'],0,2,"utf-8");             
                if($name =='财经' ||$name =='商贸'||$name =='交通'||$name =='鉴湖'||$name =='黄酒'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,2,"utf-8");             
                }else if($name =='建筑' ||$name =='机电'||$name =='交通'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,4,"utf-8");   
                }else if($name =='设计'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,5,"utf-8");   
                }else{
                    $new_dept_name[$k]['name'] = $v['dept_name'];
                }
                 $new_dept_name[$k]['dept_name'] = $v['dept_name'];
            }           
        }

        $data['dept_name']= $new_dept_name;

        // $data['dept_name']= $dept_name;

        $data['listen_type']=$this -> Select_model -> get_list(array('type'=>SelectType::ListenType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));
        
        $data['role']=WebRole::Teacher[XPHEnum::Value];
        $data['type']=2;
        $this->load->view('admin/attendListNew1',$data);
    }


    function getDatasNew($role,$type=false,$isExport = false)
    {
        $params = array();
        $connar = array();
        if (!$isExport) {
            $params = $_POST;
            $connar = $this->Attend_model->pickPages($connar, $params);
        }  

        $sub_role=explode(',', getSess()['sub_role_id']);
         array_push($sub_role, getSess()['role_id']);
        $sub_role= array_merge(array_filter($sub_role));	
        $connar['items'] = "db_attend.*";
        $connar['where']=$this->sqlEscape('(db_attend.status=?? or db_attend.status=??)',array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value]));
        // $connar['orderby'] = "db_attend.id desc ";
        $connar['orderby'] = "back_time desc, db_attend.id desc ";
        // 查询去听课数据
        if($type==1){            
            $connar['join']=array('db_admin ','db_admin.id = db_attend.listen_id');
            if($role==WebRole::SchoolLeader[XPHEnum::Value] || $role==WebRole::Admin[XPHEnum::Value]  || $role==WebRole::Manage[XPHEnum::Value]){
                    // 教务处/质量管理可以看到全校,其他人看到本分院
                    if(getSess()['dept_id']!=123 && getSess()['dept_id']!=107){
                        $connar['where'].=$this->sqlEscape(' and db_admin.dept_id=??',array(getSess()['dept_id']));
                    }
            }else if($role==WebRole::MajorUnitLeader[XPHEnum::Value]){
                  //专业负责人查看本专业的数据,不是专业负责人查看自己听课的数据
                 $connar['where'].=$this->sqlEscape(' and db_admin.major=??',array(getSess()['major']));     
            }else if($role==WebRole::Teacher[XPHEnum::Value]){
                $connar['where'].=$this->sqlEscape(' and db_attend.listen_id=??',array(getSess()['id']));
            }else{
                $connar['where'].=' and 1<>1';
            }


        }else{

            $rold_id_arr = explode(",",$role);
            // 查询个人被听课数据            
            $connar['join']=array('db_admin ','db_admin.usercode = db_attend.teacher_code');
            $connar['where'].=$this->sqlEscape(' and db_attend.teacher_code=??',array(getSess()['usercode']));
            
            //领导干部
          /*  if(count($rold_id_arr) >1 && ($rold_id_arr[0]==WebRole::SchoolLeader[XPHEnum::Value] || $rold_id_arr[1]==WebRole::UnitLeader[XPHEnum::Value] || $rold_id_arr[0]==WebRole::Admin[XPHEnum::Value]  || $rold_id_arr[0]==WebRole::Manage[XPHEnum::Value])){
                $connar['where'].=$this->sqlEscape(' and (role_id = ?? or FIND_IN_SET(??,sub_role_id) or (role_id = ?? or FIND_IN_SET(??,sub_role_id)))',array(WebRole::SchoolLeader[XPHEnum::Value],WebRole::SchoolLeader[XPHEnum::Value],WebRole::UnitLeader[XPHEnum::Value],WebRole::UnitLeader[XPHEnum::Value]));  

                // 教务处/质量管理可以看到全校,其他人看到本分院
                if(getSess()['dept_id']!=123 && getSess()['dept_id']!=107 && in_array(WebRole::UnitLeader[XPHEnum::Value], $sub_role)){
                    $connar['where'].=$this->sqlEscape(' and db_admin.dept_id=??',array(getSess()['dept_id']));
                }
                
            }else if($role==WebRole::MajorUnitLeader[XPHEnum::Value]){
                 //专业负责人查看本专业的数据
              //  $connar['where'].=$this->sqlEscape(' and role_id = ?? or FIND_IN_SET(??,sub_role_id)',array(WebRole::MajorUnitLeader[XPHEnum::Value],WebRole::MajorUnitLeader[XPHEnum::Value]));             
                if(in_array(WebRole::MajorUnitLeader[XPHEnum::Value], $sub_role)){
                      $connar['where'].=$this->sqlEscape(' and db_admin.major=??',array(getSess()['major']));  
                  } 

            }else if($role==WebRole::Teacher[XPHEnum::Value]){
              //  $connar['where'].=$this->sqlEscape(' and role_id = ?? or FIND_IN_SET(??,sub_role_id)',array(WebRole::Teacher[XPHEnum::Value],WebRole::Teacher[XPHEnum::Value]));
                if(in_array(WebRole::Teacher[XPHEnum::Value], $sub_role)){
                    $connar['where'].=$this->sqlEscape(' and db_attend.teacher_code=??',array(getSess()['usercode']));
                }              
            }else{
                $connar['where'].=' and 1<>1';
            }*/
        }
        //课程名称
        if (isset($_POST['class_name']) && $_POST['class_name'] != ''){           
            $connar['where'] .= $this->sqlLikeEscape(" and db_attend.class_name like '%??%' ", array($_POST['class_name']));
        }
        //教师名称
        if(isset($_POST['teacher_name']) && $_POST['teacher_name'] != ''){
            $connar['where'] .= $this->sqlLikeEscape(" and db_attend.teacher_name like '%??%' ", array($_POST['teacher_name']));
        }
        //听课班级
        if(isset($_POST['listen_class']) && $_POST['listen_class'] != ''){
            $connar['where'] .= $this->sqlLikeEscape(" and db_attend.listen_class like '%??%' ", array($_POST['listen_class']));
        }
        //职称
        if(isset($_POST['title'])&&$_POST['title']>-1)
        {
            $connar['where'] .= $this->sqlEscape(" and db_attend.title=?? ",array($_POST['title']));
        }
        //课程类型
        if(isset($_POST['class_type'])&&$_POST['class_type']>-1)
        {
            $connar['where'] .= $this->sqlEscape(" and db_attend.class_type=?? ",array($_POST['class_type']));
        }
        //听课督导
        if(isset($_POST['listen_name']) && $_POST['listen_name'] != '')
        {
            $connar['where'] .= $this->sqlLikeEscape(" and db_admin.username like '%??%' ",array($_POST['listen_name']));
        }
        //督导听课身份类型
        if(isset($_POST['type'])&&$_POST['type']>-1)
        {
            $connar['where'] .= $this->sqlEscape(" and db_attend.type=?? ",array($_POST['type']));
        }
        //听课类型
        if(isset($_POST['listen_type'])&&$_POST['listen_type']>-1)
        {
            $connar['where'] .= $this->sqlEscape(" and db_attend.listen_type=?? ",array($_POST['listen_type']));
        }


        if (isset($_POST['start_time']) && isset($_POST['end_time']) && $_POST['start_time'] != '' && $_POST['end_time'] != '') {

            $connar['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');

        }
            //分院名称
            if(isset($_POST['dept_name'])&&$_POST['dept_name']>-1)
        {
              $connar['where'] .= " and db_attend.dept_name like '%".$_POST['dept_name']."%'";
            // $connar['where'] .= $this->sqlEscape(" and db_attend.dept_name=?? ",array($_POST['dept_name']));
        }            
        // 听课记录
        if(isset($_POST['content']) && $_POST['content'] != '')
        {
            $connar['where'] .= $this->sqlLikeEscape(" and db_attend_record.commentary like '%??%' ",array($_POST['content']));
        }   
        //提交状态
            if (isset($_POST['is_submit'])&& $_POST['is_submit'] > -1){

                 $connar['where'] .=  $this->sqlEscape(" and db_attend.status=?? ",array($_POST['is_submit']));
            }


        if (!$isExport) {
            $data = $this->Attend_model->get_page_list($connar);
            // echo $this->db->last_query();
        } else {
            $data["ret"] = $this->Attend_model->get_list_full($connar);
        }
        foreach ($data['ret'] as $k => $v) {
           $data['ret'][$k]['listen_time'] = date('Y-m-d ', $data['ret'][$k]['listen_time']);
            $data['ret'][$k]['type_char']=(new AttendType)->show($v['type']);
            $data['ret'][$k]['status_char']=(new AttendStatus)->show($v['status']);            
            if($v['back_time']){
                $data['ret'][$k]['color']='red';
                if($v['status']==AttendStatus::Submit[XPHEnum::Value]){
                    $data['ret'][$k]['status_char']='退回后提交';
                }else{                    
                    $data['ret'][$k]['status_char']='退回中';
                }
            }
        }

        if (!$isExport) {
            echo json_encode($data);
        } else {
            $this-> load ->library('PHPExcel/PHPExcel');
            $excel = new PHPExcel();
            //公共样式
            $excel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(11); 
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setWrapText(true);
            $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(23);
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $excel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);

            $x_line=0;
            $y_line=1;
            
            //标题
            // var_dump($data['ret']);
            // $title=array('开课单位','督导听课人数','督导听课次数','校督导听课人数','校督导听课次数','教学水平平均分','教学效果平均分','教学水平90分(含)以上','教学水平80以下','教学效果90分(含)以上','教学效果80以下','教学水平最高分','教学水平最低分','教学效果最高分','教学效果最低分');
            // foreach ($title as $k => $v) {
            //     $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v);
            //     $excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line)->getFont()->setBold(true);   
            //     $x_line++;
            // }

            // $x_line=0;
            // $y_line=2;
            // //正式数据
            // foreach ($data['ret'] as $k => $v) {            
            //     foreach ($v as $k1 => $v1) {
            //         $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v1);


            //         $x_line++;
            //     }
            //     $x_line=0;
            //     $y_line++;
            // }

        //正式开始
        $excel = new PHPExcel();
        $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(15);
        
        //标题
        $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0).'1:'.PHPExcel_Cell::stringFromColumnIndex(15).'1');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).'1','课堂教学评价');
        $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
        $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $i=2;
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$i,'听课教师名称');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$i,'授课教师名称');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$i,'教学能力总分');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$i,'学生状况总分');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(4).$i,'总分');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(5).$i,'学年');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(6).$i,'学期');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(7).$i,'听课类型');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(8).$i,'课程名称');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(9).$i,'课程类型');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(10).$i,'职称');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(11).$i,'所属二级学院（部）');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$i,'年龄层次');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(13).$i,'教师属性');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(14).$i,'听课时间');
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(15).$i,'开课单位');
        
       

        $i++;
        foreach ($data['ret'] as $k => $v) {
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$i,$v['listen_name']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$i,$v['teacher_name']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$i,$v['teaching_level_score']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$i,$v['teaching_effect_score']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(4).$i,$v['score']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(5).$i,$v['academic_year']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(6).$i,$v['semester']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(7).$i,$v['type_char']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(8).$i,$v['class_name']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(9).$i,$v['class_type']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(10).$i,$v['title']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(11).$i,$v['dept_name']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$i,$v['age_groups']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(13).$i,$v['teachers_attribute']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(14).$i,$v['listen_time']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(15).$i,$v['course_units']);
           
           
            $i++;
        }
        //设置对齐
        $excel->getActiveSheet()->getStyle('A1:'.PHPExcel_Cell::stringFromColumnIndex(9).($i-1))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $excel->getActiveSheet()->getStyle('A1:'.PHPExcel_Cell::stringFromColumnIndex(0).($i-1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);


            $write = new PHPExcel_Writer_Excel2007($excel); 
            $director = "upload/export/" . date('Ymd', time()) . "/";
            if (!file_exists($director)) {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
                mkdir($director, 0777);
            }        
            $file_name ='督导听课'.date('Ymdhis').'.xlsx';           
            $write->save($director.iconv('utf-8', 'gb2312', $file_name));
            exit(retJson('返回地址',true,$director.$file_name));
            // return $data["ret"];
        }
    }

    //获取课程类型
    public function getClassType(){
        $data['class_type']=$this -> Select_model -> get_list(array('type'=>SelectType::CourseType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));
        echo json_encode($data);
    }
   

    //批量打印课题教学评价表
        /*  function printAllold(){
                $data['title'] = "督导听课评价表";
                //角色数组
                $this->load->model("Attend_model");
                $this->load->library("ProjectService/attend_service");
                $this->load->model('Select_model');
                $_POST = $_GET;
                // $connar['where'] = " db_attend.id<>1 ";
                $connar['where']=$this->sqlEscape('if(back_time is null,db_attend.STATUS = ?? or db_attend.STATUS = ??, db_attend.STATUS = ?? or db_attend.STATUS = ??)',array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Save[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
                $connar['orderby'] = "back_time desc, db_attend.id desc ";
                // $connar['items'] = "id,cc_type,created";
                $connar['items'] = "db_attend.*,db_admin.major major,db_admin.dept_name listen_dept_name,db_admin.usercode listen_code";
                $connar['join'][0]=array('db_admin ','db_admin.id = db_attend.listen_id');
                //课程名称
                if (isset($_POST['class_name']) && $_POST['class_name'] != ''){           
                    $connar['where'] .= $this->sqlLikeEscape(" and db_attend.class_name like '%??%' ", array($_POST['class_name']));
                }
                //教师名称
                if(isset($_POST['teacher_name']) && $_POST['teacher_name'] != ''){
                    $connar['where'] .= $this->sqlLikeEscape(" and db_attend.teacher_name like '%??%' ", array($_POST['teacher_name']));
                }
                //听课班级
                if(isset($_POST['listen_class']) && $_POST['listen_class'] != ''){
                    $connar['where'] .= $this->sqlLikeEscape(" and db_attend.listen_class like '%??%' ", array($_POST['listen_class']));
                }
                //职称
                if(isset($_POST['title'])&&$_POST['title']>-1)
                {
                    $connar['where'] .= $this->sqlEscape(" and db_attend.title=?? ",array($_POST['title']));
                }
                //课程类型
                if(isset($_POST['class_type'])&&$_POST['class_type']>-1)
                {
                    $connar['where'] .= $this->sqlEscape(" and db_attend.class_type=?? ",array($_POST['class_type']));
                }
                //听课督导
                if(isset($_POST['listen_name']) && $_POST['listen_name'] != '')
                {
                    $connar['where'] .= $this->sqlLikeEscape(" and db_admin.username like '%??%' ",array($_POST['listen_name']));
                }
                //督导听课身份类型
                if(isset($_POST['type'])&&$_POST['type']>-1)
                {
                    $connar['where'] .= $this->sqlEscape(" and db_attend.type=?? ",array($_POST['type']));
                }
                //听课类型
                if(isset($_POST['listen_type'])&&$_POST['listen_type']>-1)
                {
                    $connar['where'] .= $this->sqlEscape(" and db_attend.listen_type=?? ",array($_POST['listen_type']));
                }

                if (isset($_POST['start_time']) && isset($_POST['end_time']) && $_POST['start_time'] != '' && $_POST['end_time'] != '') {

                    $connar['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');

                }
                //教师所属分院名称
                if(isset($_POST['dept_name'])&&$_POST['dept_name']>-1)
                {
                    $connar['where'] .= " and db_attend.dept_name like '%".$_POST['dept_name']."%'";
                    // $connar['where'] .= $this->sqlEscape(" and (db_attend.dept_name=?? or db_attend.dept_name=??)",array(str_replace('分', '学', $_POST['dept_name']),str_replace('学', '分', $_POST['dept_name'])));
                }  
                //开课单位名称
                if(isset($_POST['course_units'])&&$_POST['course_units']>-1)
                {
                    $connar['where'] .= " and db_attend.course_units like '%".$_POST['course_units']."%'";
                    // $connar['where'] .= $this->sqlEscape(" and (db_attend.dept_name=?? or db_attend.dept_name=??)",array(str_replace('分', '学', $_POST['dept_name']),str_replace('学', '分', $_POST['dept_name'])));
                }           
                // 听课记录
                if(isset($_POST['content']) && $_POST['content'] != '')
                {
                    $connar['where'] .= $this->sqlLikeEscape(" and db_attend_record.commentary like '%??%' ",array($_POST['content']));
                }   
                //提交状态
                if (isset($_POST['is_submit'])&& $_POST['is_submit'] > -1){

                    $connar['where'] .= $this->sqlEscape(" and db_attend.status=?? ",array($_POST['is_submit']));
                }

                //提交状态
                if (isset($_POST['is_complete'])&& $_POST['is_complete'] > -1){
                    if($_POST['is_complete'] == 1){
                        // if ($v['course_units'] == '' || $v['listen_time'] == '' || $v['class_name'] == '' || $v['teacher_name'] == '' || $v['dept_name'] == '' || $v['title'] == '' || $v['teachers_attribute'] == '' || $v['class_type'] == '' || $v['listen_class'] == '' || $v['listen_address'] == '' || $v['type'] == '' || $v['listen_type'] == '' || $v['teaching_level_score'] == '0' || $v['teaching_effect_score'] == '0' || $v['score'] == '0') {
                        $connar['where'] .= $this->sqlEscape(" and (db_attend.course_units!='' and db_attend.listen_time!='' and db_attend.listen_time != '0' and db_attend.class_name!='' and db_attend.teacher_name!='' and db_attend.dept_name!='' and db_attend.listen_time!='' and db_attend.title!='' and db_attend.teachers_attribute!='' and db_attend.class_type!='' and db_attend.listen_class!='' and db_attend.listen_address!='' and db_attend.type!='' and db_attend.listen_type!='' and db_attend.teaching_level_score!='0' and db_attend.teaching_effect_score!='0' and db_attend.score!='0')",array());
                    }else{
                        $connar['where'] .= $this->sqlEscape(" and (db_attend.course_units='' or db_attend.listen_time='' or db_attend.listen_time = '0'  or db_attend.class_name='' or db_attend.teacher_name='' or db_attend.dept_name='' or db_attend.listen_time='' or db_attend.title='' or db_attend.teachers_attribute='' or db_attend.class_type='' or db_attend.listen_class='' or db_attend.listen_address='' or db_attend.type='' or db_attend.listen_type='' or db_attend.teaching_level_score='0' or db_attend.teaching_effect_score='0' or db_attend.score='0')",array());
                    }
                
            }
                //总分筛选
                if(isset($_POST['score'])&& $_POST['score'] > -1){

                    if($_POST['score'] == TotalSorce::First[XPHEnum::Value]){
                        $connar['where'] .= $this->sqlEscape(" and db_attend.score >=?? ",array(TotalSorce::First[XPHEnum::Remark])); 
                    }else if($_POST['score'] == TotalSorce::Second[XPHEnum::Value]){
                        $score = explode('-',TotalSorce::Second[XPHEnum::Remark]);
                        $connar['where'] .= $this->sqlEscape(" and db_attend.score >=??  and db_attend.score < ??  ",array($score[0],$score[1])); 
                    }else{
                        $connar['where'] .= $this->sqlEscape(" and db_attend.score < ?? ",array(TotalSorce::Third[XPHEnum::Remark])); 
                    }
                }
                $AttendList = $this->Attend_model->get_list_full($connar);

                foreach ($AttendList as $key => $value) {
                    # code...
                    $AttendList[$key]['detail']=$this->attend_service->getAttendData($value['id'],false,false,$value['cc_type']);
                    $AttendList[$key]['courseType']=$this->Select_model->get_list(array('type'=>SelectType::CourseType[XPHEnum::Value]));
            //            $data['detail'] = $this->Attend_model->get_single(array("id" => $id));
            //        }
                    if($value['cc_type'] == '2' && $value['created']>1660548484){
                        $AttendList[$key]['htmltype']= '3';
                        // $this->load->view('admin/attendEdit3', $data);
                    }else{
                        if($value['created']<1587744000){
                            // 老页面数据
                            $AttendList[$key]['htmltype']= '0';
                            // $this->load->view('admin/attendEdit', $data);
                        }elseif($value['created']>1627526560){
                            $AttendList[$key]['htmltype']= '2';
                            // 新页面
                            // 20219月新课标
                            // pri($data);exit;
                            // $this->load->view('admin/attendEdit2', $data);
                        }else{
                            // 老页面数据
                            $AttendList[$key]['htmltype']= '1';
                            // $this->load->view('admin/attendEdit1', $data);
                        }
                    }
                }

                // var_dump($AttendList);
        
                //        if ($id == 0) {
                //            $data['title'] = "新增听课";
                //            $data['detail'] = $this->Attend_model->get_single(array("id" => $id));
                //        } else {
                        
                        //   $data['detail']=$this->attend_service->getAttendData($id,false,false,$_GET['type']);
                        //   $data['courseType']=$this->Select_model->get_list(array('type'=>SelectType::CourseType[XPHEnum::Value]));
                //            $data['detail'] = $this->Attend_model->get_single(array("id" => $id));
                //        }
                    //   if($data['detail']['attend']['cc_type'] == '2' && $data['detail']['attend']['created']>1660548484){
                    //       $this->load->view('admin/attendEdit3', $data);
                    //   }else{
                        
                    //   }
                    $data['AttendList'] =  $AttendList;
        
                $this->load->view('admin/attendPrintAll', $data);
            } */
        
    
    
    
    function printAll($ids){
        $data['title'] = "督导听课评价表";
          //角色数组
        $this->load->model("Attend_model");
        $this->load->library("ProjectService/attend_service");
        $this->load->model('Select_model');
        $connar['where']= "id in (".$ids.")";
        $connar['orderby'] = "back_time desc, db_attend.id desc ";
        $AttendList = $this->Attend_model->get_list_full($connar);
        // echo $this->db->last_query();
        foreach ($AttendList as $key => $value) {   
            # code...
            $AttendList[$key]['detail']=$this->attend_service->getAttendData($value['id'],false,false,$value['cc_type']);
            $AttendList[$key]['courseType']=$this->Select_model->get_list(array('type'=>SelectType::CourseType[XPHEnum::Value]));
    //            $data['detail'] = $this->Attend_model->get_single(array("id" => $id));
    //        }
            if($value['cc_type'] == '2' && $value['created']>1660548484){ //2022-08-15 15:28:04之后的实训课的数据
                $AttendList[$key]['htmltype']= '3';
                // $this->load->view('admin/attendEdit3', $data);
            }else if($value['cc_type'] == '3'){ //2023-12-12 15:28:04之后的思政课的数据
                $AttendList[$key]['htmltype']= '4';
                // $this->load->view('admin/attendEdit3', $data);
            }else if($value['cc_type'] == '4'){ //2023-12-12 15:28:04之后的思政课的数据
                $AttendList[$key]['htmltype']= '5';
                // $this->load->view('admin/attendEdit3', $data);
            }else{ //理论课的数据
                if($value['created']<1587744000){ //2020-04-25之前的数据
                    // 老页面数据
                    $AttendList[$key]['htmltype']= '0';
                    // $this->load->view('admin/attendEdit', $data);
                }elseif($value['created']>1627526560){ //2021-07-29 10:42:40之后的数据
                    $AttendList[$key]['htmltype']= '2';
                    // 新页面
                    // 20219月新课标
                    // pri($data);exit;
                    // $this->load->view('admin/attendEdit2', $data);
                }else{ //2020-04-25之后到2021-07-29 10:42:40之前的数据
                    // 老页面数据
                    $AttendList[$key]['htmltype']= '1';
                    // $this->load->view('admin/attendEdit1', $data);
                }
            }
        }
        $data['AttendList'] =  $AttendList;
        $this->load->view('admin/attendPrintAll', $data);
        // var_dump($ids);
    }

}
